<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Purchase/index')}">列表</a></li>
        <li class="active"><a >编辑</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Purchase/addPost')}">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 合同号:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" name="ht_num" value="{$vo.ht_num|default=''}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 订货日期:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control js-date" name="order_time"
                       value="{:date('Y-m-d',$vo['order_time'])}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 合同金额:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control " name="ht_price"
                       value="{$vo.ht_price|default=''}">
            </div>
        </div>     <div class="form-group">
        <label class="col-sm-2 control-label"><span class="form-required"></span> 发票金额:</label>
        <div class="col-md-6 col-sm-10">
            <input autocomplete="off" type="text" class="form-control " name="invoice"
                   value="{$vo.invoice|default=''}">
        </div>
    </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 是否完结:</label>
            <div class="col-md-6 col-sm-10">
                <select name="is_end" class="form-control">
                    <option value="">请选择</option>
                    <option
                    <if isset($vo.is_end)&&$vo.is_end=='2'>selected</if>
                    value="2">否</option>
                    <option
                    <if isset($vo.is_end)&&$vo.is_end=='1'>selected</if>
                    value="1">是</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 图片附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly style="display: inline-block;width:80%;" class="form-control" name="image_enclosure"
                       id="image_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('图片上传','#image_enclosureCnt','#image_enclosure','image');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="image_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 文件附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly style="display: inline-block;width:80%;" class="form-control" name="file_enclosure"
                       id="file_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('文件上传','#file_enclosureCnt','#file_enclosure','file');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="file_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 备注:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" name="remark" value="{$vo.remark|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 其他:</label>
            <div class="col-md-6 col-sm-10"><a class="btn btn-xs btn-primary" onclick="addkun(this)">增加子项</a></div>
        </div>

        <div class="form-group" >
            <table class="table table-hover table-bordered table-list" id="lisjj">
                <tr>
                    <th>订单号</th>
                    <th>名称</th>
                    <th>牌号</th>
                    <th>钢卷号</th>
                    <th>厚</th>
                    <th>宽</th>
                    <th>长</th>
                    <th>数量</th>
                    <th>吨重</th>
                    <th>到货数量</th>
                    <th>到货重量</th>
                    <th>单价</th>

                    <th>采购钢厂</th>
                    <th>交货月</th>
                    <th>到货地点</th>
                </tr>
                <foreach name="$pasub" item="vo" index="index">
                <tr>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][order_id]"
                               value="{$vo.order_id}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][c_name]"
                               value="{$vo.c_name}">
                    </td>
                    <td>
                        <select name="date[{$index}][steel_grade_id]" class="form-control selectpicker" data-live-search="true">
                            <option value="0">请选择</option>

                        </select>
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][coil_num]"
                               value="{$vo.coil_num}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][d]"
                               value="{$vo.d}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][w]"
                               value="{$vo.w}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][h]"
                               value="{$vo.h}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][num]"
                               value="{$vo.num}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][weight]"
                               value="{$vo.weight}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][arr_num]"
                               value="{$vo.arr_num}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][arr_weight]"
                               value="{$vo.arr_weight}">
                    </td>

                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][unit_price]"
                               value="{$vo.unit_price}">
                    </td>

                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][steelmill]"
                               value="{$vo.steelmill}">
                    </td>
                    <td>
                        <input autocomplete="off" type="text" class="form-control js-datetime" name="date[{$index}][delivery_month]"
                               value="{$vo.delivery_month}">
                    </td>
                    <td><input placeholder="" type="text" class="form-control" name="date[{$index}][arr_place]"
                               value="{$vo.arr_place}">
                    </td>

                </tr>
                </foreach>
            </table>


        </div>
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            <a class="btn btn-default" href="{:url('Purchase/index')}">返回</a>
        </div>
    </form>

</div>
<script src="/static/js/admin.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script>
    coil_count = 100;
    function addkun(obj) {
        var steel_grade_id_arr = new Array();
        steel_grade_id_arr = {$steel_grade_arr_da1};
        ht='';
        for(let i = 0; i　< steel_grade_id_arr.length; i++) {
            ht=ht+'<option value="'+steel_grade_id_arr[i]['id']+'">'+steel_grade_id_arr[i]['name']+'</option>'
        }
        // html = '            <table class="table table-hover table-bordered table-list" id="div_is_starting_price_' + coil_count + '">\n' +
        //     '                <tr>\n' +
        //     '                    <th>订单号</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][order_id]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>名称</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][c_name]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>牌号</th>\n' +
        //     '                    <td>\n' +
        //     '                        <select name="date[' + coil_count + '][steel_grade_id]" class="form-control selectpicker" data-live-search="true">\n' +
        //     '                            <option value="0">请选择</option>\n' +
        //     ht+
        //     '\n' +
        //     '                        </select>\n' +
        //     '                    </td>\n' +
        //     '                    <th>钢卷号</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][coil_num]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>厚</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][d]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>宽</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][w]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     // '                </tr>\n' +
        //     // '                <tr>\n' +
        //     '                    <th>长</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][h]"\n' +
        //     '                               value="C">\n' +
        //     '                    </td>\n' +
        //     '                    <th>数量</th>\n' +
        //     '                    <td><input placeholder="" type="number" class="form-control" name="date[' + coil_count + '][num]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>吨重</th>\n' +
        //     '                    <td><input placeholder="" type="number" class="form-control" name="date[' + coil_count + '][weight]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>到货数量</th>\n' +
        //     '                    <td><input placeholder="" type="number" class="form-control" name="date[' + coil_count + '][arr_num]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>到货重量</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][arr_weight]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>单价</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][unit_price]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     // '                </tr>\n' +
        //     // '                <tr>\n' +
        //
        //     '                    <th>合同金额</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][ht_price]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>发票金额</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][Invoice]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>采购钢厂</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][steelmill]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>交货月</th>\n' +
        //     '                    <td>\n' +
        //     '                        <input  type="text" class="js-bootstrap-date form-control" name="date[' + coil_count + '][delivery_month]"\n' +
        //     '                               value="">\n' +
        //     '                    </td>\n' +
        //     '                    <th>到货地点</th>\n' +
        //     '                    <td><input placeholder="" type="text" class="form-control" name="date[' + coil_count + '][arr_place]"\n' +
        //     '                               value="">\n' +
        //     '<td><a class="btn btn-xs btn-danger" onClick="remove(\'div_is_starting_price_' + coil_count + '\')">移除</a></td>' +
        //     '                    </td>\n' +
        //     '\n' +
        //     '                </tr>\n' +
        //     '            </table>\n' +
        //     '            <br>';
        // console.log(11)


        html='  <tr id="div_is_starting_price_' + coil_count + '">\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][order_id]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][c_name]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td>\n' +
            '                        <select name="date['+coil_count+'][steel_grade_id]" class="form-control selectpicker" data-live-search="true">\n' +
            '                            <option value="0">请选择</option>\n' +

            ht+
            '\n' +
            '                        </select>\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][coil_num]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][d]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][w]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][h]"\n' +
            '                               value="C">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][num]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][weight]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][arr_num]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][arr_weight]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][unit_price]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][steelmill]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td>\n' +
            '                        <input autocomplete="off" type="text" class="form-control js-datetime" name="date['+coil_count+'][delivery_month]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '                    <td><input placeholder="" type="text" class="form-control" name="date['+coil_count+'][arr_place]"\n' +
            '                               value="">\n' +
            '                    </td>\n' +
            '\n' +
            '                </tr>';

        jQuery('#lisjj').append(html);
        // $('.js-bootstrap-date').datepicker();
        // obj.insertAdjacentHTML('beforebegin',html)
        $('.selectpicker').selectpicker('render');
        // $('.js-bootstrap-date').datepicker();
        coil_count++
    }
    function remove(ids) {
        console.log(ids)
        ids = "#" + ids;
        jQuery(ids).remove();
        // $("#div1").empty();
    }
    //预览图片
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '图片预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除图片
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }//预览
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '文件预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }</script>
</body>
</html>